DEFINITION MODULE CoreDump; (* Franz Kronseder / ETHZ / 04.07.85 *)
                            (* last modified 06.07.85 *)
                            (* memory dump mechanism for the Modula2 runtime *)
                            (* modula SYSTEMX on Macintosh *)
FROM SYSTEM IMPORT ADDRESS;
EXPORT QUALIFIED DH, DHTyp, BytesPerBlock, errorActive, dumpActive, dumpRequest,
                 HALTSP, MAINPD,Dump,DumpInhibit, ErrTextType, ErrorText, InclDump, ExclDump;

CONST maxLayer = 10; maxSegment = maxLayer+1; fnlength = 63;
      (* Constants for Heap dump *)
      MaxMem = 1048576;                         (* 1MB *)
      BytesPerBlock = 512;                      (* Dumped block size *)
      DumpMapSize = MaxMem DIV BytesPerBlock;   (* Bits in dump map, 2048 *)
      DumpMapEl = DumpMapSize DIV 16;           (* = size of BITSET *)


TYPE FileAddress = ADDRESS;    (* 32 bits *)
     DHTyp = RECORD                  (* dump header, layout as written on the dump core file *)
                ErrorMP    : ADDRESS;                             (* error part *)
                ErrorPC    : ADDRESS;
                ErrorPD    : ADDRESS;
                ErrorCode  : INTEGER;
                segments   : ARRAY [0..maxSegment-1] OF RECORD    (* dump part *)
                                                         fwa, lwa1  : ADDRESS;
                                                         fileptr    : FileAddress;
                                                        END;
                CurrentLayer : CARDINAL;                          (* loader part *)
                HeapBlockStart : FileAddress;
                DumpMap    : ARRAY [0..DumpMapEl-1] OF BITSET;
                StackBase,StackTop   : ADDRESS;
                layers     : ARRAY [0..maxLayer-1] OF
                              RECORD Base,Top: ADDRESS; END;  (* fwa, lwa+1 *)
                CurrentLoadFile: ARRAY [0..fnlength-1] OF CHAR;
                dumpValid  : BOOLEAN;                             (* dump part *)
              END;(*DHTyp 538 Bytes *)


VAR
  errorActive : BOOLEAN;     (* semaphore indicating DH is occupied by an error *)
  dumpActive  : BOOLEAN;     (* semaphore indicating Dump is active             *)
  dumpRequest : BOOLEAN;     (* parameter to ErrorRoutine, requesting a dump    *)

  DH : DHTyp; (* Dump Header *)

VAR HALTSP        : ADDRESS;      (* emergency SP for final error reporting      *)
VAR MAINPD        : ADDRESS;      (* for identification of the main process      *)
                                  (* also emergency PD for final error reporting *)

PROCEDURE Dump; (* write a core dump to disk *)

PROCEDURE DumpInhibit(option:INTEGER):CARDINAL;
 (* modify the Dump-Inhibit, or the StopInhibit counter, clear it, or inquire it *)
 (* option = +1: disable, -1: enable dump. =0: clear/enable. =2 inquire value *)

PROCEDURE InclDump(p: ADDRESS; size: ADDRESS);
(* include a used storage area into the dumpable memory, from p to p+size-1 *)

PROCEDURE ExclDump (p: ADDRESS; size: ADDRESS);
(* exclude an unused storage area from the dumpable memory, from p to p+size-1 *)

TYPE ErrTextType = ARRAY [0..49] OF CHAR;

PROCEDURE ErrorText (err: INTEGER; VAR text: ErrTextType);
(* text: ARRAY [0..49] OF CHAR *)
(* get an error text corresponding to a HALTX number *)

END CoreDump.
